package com.yn.club.subject.domain.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yn.club.common.util.PageReq;
import com.yn.club.common.util.PageResp;
import java.io.Serializable;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.yn.club.subject.domain.entity.SubjectInfoDO;
import com.yn.club.subject.infra.basic.entity.SubjectInfo;
import com.yn.club.subject.domain.service.SubjectInfoDomainService;
import com.yn.club.subject.infra.basic.service.SubjectInfoService;
import com.yn.club.subject.domain.convert.SubjectInfoDomainConverter;


/**
 * 题目信息表(SubjectInfo)表服务接口实现类
 *
 * @author YN
 * @since 2025-01-21 17:36:34
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class SubjectInfoDomainServiceImpl implements SubjectInfoDomainService {

  private final SubjectInfoService subjectInfoService;
  private final SubjectInfoDomainConverter subjectInfoDomainConverter;


  /**
   * 分页
   */
  @Override
  public PageResp<SubjectInfoDO> page(PageReq pageReq, SubjectInfoDO query){
    QueryWrapper<SubjectInfo> querywrapper = new QueryWrapper<SubjectInfo>()
        .eq(query.getId() != null, "id", query.getId())
        .orderByDesc("id");
        
    Page<SubjectInfo> page = subjectInfoService.page(
      new Page<>(pageReq.getPageIndex(),pageReq.getPageSize()),querywrapper);
    List<SubjectInfo> list = page.getRecords();  
    return PageResp.of(page,subjectInfoDomainConverter.convertEntityToDo(list));
  }

  /**
   * 新增数据
   */
  @Override
  public Boolean insert(SubjectInfoDO obj){
    SubjectInfo subjectInfo = subjectInfoDomainConverter.convertDoToEntity(obj);
    return subjectInfoService.save(subjectInfo);
  };


  /**
   * 更新数据
   */
  @Override
  public Boolean updateById(SubjectInfoDO obj){
    SubjectInfo subjectInfo = subjectInfoDomainConverter.convertDoToEntity(obj);
    return subjectInfoService.updateById(subjectInfo);
  };

  /**
   * 批量删除
   */
  @Override
  public Boolean delete(List<Integer> ids){
    return subjectInfoService.removeByIds(ids);
  };

  /**
   * 根据id查找
   */
  @Override
  public SubjectInfoDO getById(Serializable id){
    SubjectInfo subjectInfo = subjectInfoService.getById(id);
    return  subjectInfoDomainConverter.convertEntityToDo(subjectInfo);
  };


}

